/**
 * 
 * h获取字符串中连续最多的字符 使用嵌套循环
 */

type resType = {
    chart:string,
    length:number
}

const getRepeatMaxLength = (str:string):resType | null =>{
    if(str === '') return null
    let res:resType = {
        chart:'',
        length:0
    }
    let curLength = 0

    for(let i = 0;i<str.length;i++){
        
        for(let j = i;j<str.length;j++){
            if(str[i] === str[j]){
                curLength ++
            }
            if(str[i] != str[j]){
                if(res.length < curLength){
                    res.chart = str[i]
                    res.length = curLength
                }
                curLength = 0
                i = j
            }
        }
    }
    return res
}


/**
 * 
 * 使用指针进行判断
 */

const getRepeatMaxLengthByPoint = (str:string):resType | null =>{
    if(str === '') return null
    let res:resType = {
        chart:'',
        length:0
    }
    let curLength = 0
    let i = 0
    let j = 0
    for(;i<str.length;i++){
        if(str[j] === str[i]){
            curLength++
        }
        if(str[j] !== str[i]){
            if(res.length < curLength){
                res.chart = str[i]
                res.length = curLength
            }
            j = i
            curLength = 0
        }
    }
    return res
}


const str = 'aaaaaaaaaaabbbbbbbbcdferzzzzz'
console.log(getRepeatMaxLengthByPoint(str))